<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<meta http-equiv="Cache-Control" content="no-siteapp">
<link rel="stylesheet" href="../../../static/layui/css/layui.css" media="all" />
<link rel="stylesheet" href="../../../static/css/public.css" media="all" />
<link rel="stylesheet" href="../../../static/plugin/zTree/css/zTreeStyle/zTreeStyle.css" type="text/css">
</head>
<body class="childrenBody">
	<form class="layui-form">
		<blockquote class="layui-elem-quote quoteBox"> 
				<a class="layui-btn layui-btn-normal insert-btn"  >添加</a> 
			</div>
		</blockquote>
		<table id="list" lay-filter="list"></table>
		<div class="list-page" id="page"></div>
	</form>
	<div id="treeDiv" class="menuContent" style="display: none; position: absolute; background: white; border: 1px black solid; z-index: 999">
		<ul id="departmentTree" class="ztree" style="margin-top: 0; width: 160px;"></ul>
	</div>
 
	<script type="text/javascript" src="../../../static/js/jquery-2.1.1.min.js"></script>
	<script type="text/javascript" src="../../../static/layui/layui.js"></script>
	<script type="text/javascript" src="../../../static/custom/js/common.js"></script>
	<script type="text/javascript">
		layui.use([ 'form', 'layer', 'laydate', 'table', 'laypage', 'laytpl' ], function() {
			var listApi = '../../../accounting/cwCpttypes/list';
			var chgStateApi = '../../../accounting/cwCpttypes/chgState';
			var toInsertHtml = 'insert.html';
			var cols = [ [ {
				//type : "checkbox",
				fixed : "left",
				width : 50,
				title : '<input type="checkbox" lay-skin="primary"  id="check-all" class="check-all" lay-filter="check-all">',
				templet : function(d) {
					var str = '';
					if (!hasProtect(d)) {
						str += '<input type="checkbox" lay-skin="primary" class="check-one"  value="'+d.id+'" lay-filter="check-one">';
					} else {
						str += '<input type="checkbox" lay-skin="primary" class="check-one"  value="'+d.id+'" lay-filter="check-one" disabled >';
					}
					return str;
				}
			}, {
				field : 'cpttpname',
				title : '账户名称',
				align : 'center'
			}, {
				field : 'cardno',
				title : '卡号',
				align : "center"
			}, {
				field : 'starttime',
				title : '启用时间',
				align : 'center'
			}, {
				field : 'endtime',
				title : '停用时间',
				align : 'center'
			},{
				field : 'descb',
				title : '备注',
				align : 'center'
			}, {
				title : '操作',
				fixed : "right",
				align : "center",
				width : 300,
				templet : function(d) { 
					var str = '';
					if (hasPermission('004000050002', d)) {
						console.log(  d   )
						if(d.endtime){
							str += '<a class="layui-btn layui-btn-xs" lay-event="stop">启用</a>';
						}else{
							str += '<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="stop">停用</a>';
						}
					}
					return str;
				}
			} ] ];
			var pram = merger(constant.page.toUri(), getsearchVal());
			var form = layui.form, layer = parent.layer === undefined ? layui.layer : top.layer;
			var $ = layui.jquery;
			var laytpl = layui.laytpl;
			var table = layui.table;
			var laypage = layui.laypage;
			var laydate = layui.laydate;
			tableIns = table.render({
				elem : '#list',
				cellMinWidth : constant.table.cellMinWidth,
				page : false,
				height : constant.table.height,
				cols : cols,
				done : function(res, page, count) {
					checkAll(form);
				}
			});

			//用户列表
			listLoad(pram);
			function listLoad(data) {
				loadAjax( listApi, "get", data, function(response) {
					baseCallBack(response, function(response) {
						table.reload("list", {
							data : response.data.records
						})
						var page = laypage.render({
							elem : 'page',
							limits : constant.page.limits,
							limit : response.data.size,
							layout : constant.page.layout,
							curr : response.data.current,
							count : response.data.total,
							jump : function(obj, first) {
								if (!first) {
									pram = merger(constant.page.toUri(obj), getsearchVal());
									listLoad(pram);
								}
							}
						});
					});
				});
			}
			
			laydate.render({
				elem : '#starttime' //指定元素
			});
			laydate.render({
				elem : '#endtime' //指定元素
			});
		 
			//添加
			$(".insert-btn").click(function() {
				openAreaLayer("添加资金账户", toInsertHtml, "600px", "450px", true);
			});

			//列表操作
			table.on('tool(list)', function(obj) {
				var layEvent = obj.event;
				var data = obj.data;
			     if (layEvent === 'stop') {
					//删除
					confirmLayer('提示信息', '确定stop？', function(confirm, index) {
						loadAjax( chgStateApi + "/" + data.id, "get", null, function(response) {
							baseCallBack(response, function(response) {
								layer.msg(response.msg);
								listLoad(pram);
								confirm.close(index);
							});
						});
					})
				}
			});
 
		})
	</script>
</body>
</html>